<?php $this->headScript()
	->captureStart()?>
	$(document).ready(function(){
	$("#main_body tbody tr:even").addClass('even');
	$("#main_body tbody tr:odd").addClass('odd');
	});
<?php $this->headScript()->captureEnd()?>
<?php $this->headStyle()->captureStart()?>
#main_body table{background:#ccc;margin:5px;}
#main_body td {padding:3px;}
.even {background:#fff}
.odd {background:#ffc}
<?php $this->headStyle()->captureEnd()?>

<form name ='myform' action='<?php echo $this->route('index')?>' method='post'>
<div><input type=submit name='act' value='<?php echo $this->translate('browsemode')?>'> <input type=submit name='act' value='<?php echo $this->translate('appendmode')?>'>
<?php if ( isset($_POST['act']) and  $_POST['act']== $this->translate('editmode')): ?>
<input type=submit name='act' value='<?php echo $this->translate('save')?>' onClick="this.form.action='<?php echo $this->baseScript?>/edit';" style='background: yellow'>
<?php else: ?>
<input type=submit name='act' value='<?php echo $this->translate('editmode')?>'>
<?php endif; ?>
</div>
<?php $i=0; ?>
<div id='main_body'>
<table>
	<thead>
	<tr>
	<th><?php echo $this->translate('sn')?></th>
	<th><?php echo $this->translate('rank')?></th>
	<th><?php echo $this->translate('name')?></th>
	<th><?php echo $this->translate('phone_branch')?></th>
	<th><?php echo $this->translate('phone')?></th>
	<th><?php echo $this->translate('memo')?></th>
	<th align='center'><?php echo $this->translate('act')?></th>
	</tr>
	</thead>
	<tbody>
	<?php if ( isset($_POST['act']) and$_POST['act'] == $this->translate('appendmode')): ?>
	<tr class="nom_1">
		<td align='center'></td>
		<td align='center'>
		<input type="text" name="rank" size="3" value="">
		</td>
		<td align='center'>
		<input type="text" name="name" size="10" value="">
		</td>
		<td align='center'>
		<input type="text" name="phone_branch"  size="10" value="">
		</td>
		<td align='center'>
		<input type="text" name="phone" size="10" value="">
		</td>
		<td align='center'>
		<input type="text" name="memo" size="10" value="">
		</td>
		<td align='center'>
		<input type="submit" name="act" value="<?php echo $this->translate('append')?>" style='background: yellow' onClick="this.form.action='<?php echo $this->baseScript?>/add';">
		</td>
		</tr>
	<?php endif ?>
	<?php if ( isset($_POST['act']) and $_POST['act'] == $this->translate('editmode')): ?>
	<!-- 修改模式 -->
	<?php foreach($this->data as $val): ?>
		<tr class="nom_<?php echo $i++%2+1?>">
		<td align='center'><?php echo $val['sn']?></td>
		<td align='center'>
		<input type="text" name="rank[<?php echo $val['sn']?>]" id="rand_<?php echo $val['sn']?>" size="3" value="<?php echo $val['rank']?>">
		</td>
		<td align='center'>
		<input type="text" name="name[<?php echo $val['sn']?>]" id="name_<?php echo $val['sn']?>" size="10" value="<?php echo $this->escape($val['name'])?>">
		</td>
		<td align='center'>
		<input type="text" name="phone_branch[<?php echo $val['sn']?>]" id="phone_branch_<?php echo $val['sn']?>" size="10" value="<?php echo $this->escape($val['phone_branch'])?>">
		</td>
		<td align='center'>
		<input type="text" name="phone[<?php echo $val['sn']?>]" id="phone_<?php echo $val['sn']?>" size="10" value="<?php echo $this->escape($val['phone'])?>">
		</td>
		<td align='center'>
		<input type="text" name="memo[<?php echo $val['sn']?>]" id="memo_<?php echo $val['sn']?>" size="10" value="<?php echo $this->escape($val['memo'])?>">
		</td>
		<td align='center'>
		-
		</td>
		</tr>
	<?php endforeach; ?>

	<?php else: ?>
	<!-- browse mode-->
	<?php foreach($this->data as $val): ?>
		<tr class="nom_<?php echo $i++%2+1?>">
		<td align='center'><?php echo $val['sn']?></td>
		<td align='center'><?php echo $val['rank']?></td>
		<td><?php echo $val['name']?></td>
		<td align='center'><?php echo $val['phone_branch']?></td>
		<td align='center'><?php echo $val['phone']?></td>
		<td align='center'><?php echo $val['memo'] ?></td>
		<td align='center'>

		<?php if(!in_array($val['sn'],array_keys($this->title_count))): ?>
		<a href='<?php echo $this->baseScript?>/delete/sn/<?php echo $val['sn']?>'
		 onClick="return confirm('<?php echo sprintf($this->translate('confirm  delete %s record'),$val->name) ?>');"><?php echo $this->translate('delete')?></a>
		<?php else: ?>
		 <?php echo  sprintf($this->translate('contain %d title configure'),$this->title_count[$val['sn']])?>
		<?php endif ?>
		</td>
		</tr>
	<?php endforeach; ?>
	<?php endif; ?>
	</tbody>
	</table>
	</div>
	</form>
